<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('新人列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <p>新人手机号：</p>
                            <input type="text" name="couplePhone"/>
                        </li>
                        <li>
                            <p>新郎姓名：</p>
                            <input type="text" name="coupleGroomname"/>
                        </li>
                        <li>
                            <p>新娘姓名：</p>
                            <input type="text" name="coupleBridename"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:couple:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:couple:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:couple:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:couple:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:couple:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:couple:remove')}]];
    var disableFlag = [[${@permission.hasPermi('system:couple:state')}]];
    var prefix = ctx + "user/couple";
    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            exportUrl: prefix + "/export",
            modalName: "新人",
            columns: [{
                checkbox: true
            },
                {
                    field : 'coupleId',
                    title : '新人ID',
                },
                {
                    field : 'couplePhone',
                    title : '新人手机号'
                },
                {
                    field : 'coupleGroomname',
                    title : '新郎姓名'
                },
                {
                    field : 'coupleBridename',
                    title : '新娘姓名'
                },
                {
                    field : 'coupleEmail',
                    title : '新人邮箱'
                },
                {
                    field : 'coupleRegdate',
                    title : '注册时间'
                },
                {
                    field : 'coupleState',
                    title : '账号状态',
                    formatter:function (value,row,index) {
                        if(value==2){
                            return"<span style='color:red;'>禁用</span>";
                        }
                        return "正常";
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];

                        if(row.coupleState==2){
                        actions.push('<a class="btn btn-success btn-xs ' + disableFlag+ '" href="javascript:void(0)" onclick="updateState(this,' + row.coupleId + ',' + row.coupleState + ')">启用账号</a> ');
                        }else {
                            actions.push('<a class="btn btn-danger btn-xs ' + disableFlag + '" href="javascript:void(0)" onclick="updateState(this,' + row.coupleId + ',' + row.coupleState + ')">禁用账号</a>');

                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
    // 修改状态，禁用和启用
    function updateState(obj, coupleId, coupleState) {
        if (coupleState == 2) {
            coupleState = 1;
        } else {
            coupleState = 2;
        }
        $.post(prefix + "/updateState", {"coupleId": coupleId, "coupleState": coupleState}, function (data) {
            if (data.code == 0) {
                $.table.refresh();
            } else {
                $.modal.msgSuccess("操作失败");
            }
        }, "json");
    }
    var oldValue = 100;
</script>
</body>
</html>